﻿// Decompiled with JetBrains decompiler
// Type: pvdcd.DetailView
// Assembly: pvdcd, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 8BE7F426-72A0-448B-ADB3-CA2AC8E1D830
// Assembly location: C:\Users\KasimGulcan\Desktop\Kosgeb\DynaCAD\Project\DynaCAD\bin\Debug\pvdcd.dll

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
using XamlEditor;

namespace pvdcd
{
  [Serializable]
  public class DetailView
  {
    public bool IsTable;
    public Point? DetailViewPosition;
    public double? DetailViewScale;
    public List<TableProperty> TableVeriables;
    public string TableTitle;
    [NonSerialized]
    public Canvas Detail;
    [NonSerialized]
    public Table DetailTable;

    public DetailView()
    {
      this.Detail = new Canvas();
      this.IsTable = false;
      this.DetailViewPosition = new Point?();
      this.DetailViewScale = new double?();
      this.TableVeriables = new List<TableProperty>();
      this.TableTitle = "";
      this.DetailTable = new Table();
    }

    public static List<Canvas> GetDetailViewCanvas(List<DetailView> DVL)
    {
      double length = 110.0;
      List<Canvas> list = new List<Canvas>();
      Canvas canvas1 = new Canvas();
      list.Add(canvas1);
      foreach (DetailView detailView in DVL)
      {
        double num1 = 1.0;
        if (detailView.Detail.Width > 741.0)
          num1 = 741.0 / detailView.Detail.Width;
        if (detailView.IsTable)
        {
          if (detailView.Detail.Width < 300.0)
          {
            if (detailView.Detail.Height > 870.0)
            {
              double num2 = 870.0 / detailView.Detail.Height;
              if (num2 < num1)
                num1 = num2;
            }
          }
          else if (detailView.Detail.Height + 26.0 + 45.0 + (double) (15 * detailView.TableVeriables.Count) > 870.0)
          {
            double num2 = (double) (870 - (71 + 15 * detailView.TableVeriables.Count)) / detailView.Detail.Height;
            if (num2 < num1)
              num1 = num2;
          }
        }
        else if (detailView.Detail.Height > 870.0)
        {
          double num2 = 870.0 / detailView.Detail.Height;
          if (num2 < num1)
            num1 = num2;
        }
        if (detailView.IsTable)
        {
          if (detailView.Detail.Width * num1 < 360.0)
          {
            if (length + detailView.Detail.Height * num1 < 1000.0)
            {
              Canvas canvas2 = (Canvas) CloneUIElement.cloneElement((UIElement) detailView.Detail);
              Canvas.SetTop((UIElement) canvas2, length);
              Canvas.SetLeft((UIElement) canvas2, (794.0 - (detailView.Detail.Width * num1 + 380.0)) / 2.0 - 26.0);
              canvas2.RenderTransform = (Transform) new ScaleTransform(num1, num1);
              list[list.Count - 1].Children.Add((UIElement) canvas2);
              FlowDocumentReader flowDocumentReader = new FlowDocumentReader();
              flowDocumentReader.Width = 999999.0;
              flowDocumentReader.Document = DetailView.GetTable(detailView.TableVeriables, detailView.TableTitle);
              list[list.Count - 1].Children.Add((UIElement) flowDocumentReader);
              Canvas.SetLeft((UIElement) flowDocumentReader, (794.0 - (detailView.Detail.Width * num1 + 420.0)) / 2.0 + 26.0 + detailView.Detail.Width * num1);
              Canvas.SetTop((UIElement) flowDocumentReader, length);
              length = length + detailView.Detail.Height * num1 + 13.0;
            }
            else
            {
              list.Add(new Canvas());
              length = detailView.Detail.Height * num1 + 113.0;
              Canvas canvas2 = (Canvas) CloneUIElement.cloneElement((UIElement) detailView.Detail);
              canvas2.RenderTransform = (Transform) new ScaleTransform(num1, num1);
              Canvas.SetTop((UIElement) canvas2, 110.0);
              Canvas.SetLeft((UIElement) canvas2, 26.0);
              list[list.Count - 1].Children.Add((UIElement) canvas2);
              FlowDocumentReader flowDocumentReader = new FlowDocumentReader();
              flowDocumentReader.Document = DetailView.GetTable(detailView.TableVeriables, detailView.TableTitle);
              flowDocumentReader.Width = 999999.0;
              list[list.Count - 1].Children.Add((UIElement) flowDocumentReader);
              Canvas.SetLeft((UIElement) flowDocumentReader, 39.0 + detailView.Detail.Width * num1);
              Canvas.SetTop((UIElement) flowDocumentReader, 110.0);
            }
          }
          else if (length + detailView.Detail.Height * num1 + 45.0 + (double) (detailView.TableVeriables.Count * 15) + 26.0 < 1000.0)
          {
            Canvas canvas2 = (Canvas) CloneUIElement.cloneElement((UIElement) detailView.Detail);
            Canvas.SetTop((UIElement) canvas2, length);
            Canvas.SetLeft((UIElement) canvas2, (797.0 - detailView.Detail.Width * num1) / 2.0);
            canvas2.RenderTransform = (Transform) new ScaleTransform(num1, num1);
            list[list.Count - 1].Children.Add((UIElement) canvas2);
            FlowDocumentReader flowDocumentReader = new FlowDocumentReader();
            flowDocumentReader.Width = 999999.0;
            flowDocumentReader.Document = DetailView.GetTable(detailView.TableVeriables, detailView.TableTitle);
            list[list.Count - 1].Children.Add((UIElement) flowDocumentReader);
            Canvas.SetLeft((UIElement) flowDocumentReader, 39.0);
            Canvas.SetTop((UIElement) flowDocumentReader, length + detailView.Detail.Height + 13.0);
            length = length + detailView.Detail.Height * num1 + 45.0 + (double) (detailView.TableVeriables.Count * 15) + 26.0;
          }
          else
          {
            list.Add(new Canvas());
            length = detailView.Detail.Height * num1 + 45.0 + (double) (detailView.TableVeriables.Count * 15) + 136.0;
            Canvas canvas2 = (Canvas) CloneUIElement.cloneElement((UIElement) detailView.Detail);
            Canvas.SetTop((UIElement) canvas2, 110.0);
            Canvas.SetLeft((UIElement) canvas2, (797.0 - detailView.Detail.Width * num1) / 2.0);
            canvas2.RenderTransform = (Transform) new ScaleTransform(num1, num1);
            list[list.Count - 1].Children.Add((UIElement) canvas2);
            FlowDocumentReader flowDocumentReader = new FlowDocumentReader();
            flowDocumentReader.Width = 999999.0;
            flowDocumentReader.Document = DetailView.GetTable(detailView.TableVeriables, detailView.TableTitle);
            list[list.Count - 1].Children.Add((UIElement) flowDocumentReader);
            Canvas.SetLeft((UIElement) flowDocumentReader, 39.0);
            Canvas.SetTop((UIElement) flowDocumentReader, 123.0 + detailView.Detail.Height * num1);
          }
        }
        else if (length + detailView.Detail.Height * num1 < 1000.0)
        {
          Canvas canvas2 = (Canvas) CloneUIElement.cloneElement((UIElement) detailView.Detail);
          Canvas.SetTop((UIElement) canvas2, length);
          Canvas.SetLeft((UIElement) canvas2, (797.0 - detailView.Detail.Width * num1) / 2.0);
          length = length + detailView.Detail.Height * num1 + 13.0;
          canvas2.RenderTransform = (Transform) new ScaleTransform(num1, num1);
          list[list.Count - 1].Children.Add((UIElement) canvas2);
        }
        else
        {
          list.Add(new Canvas());
          length = detailView.Detail.Height * num1 + 113.0;
          Canvas canvas2 = (Canvas) CloneUIElement.cloneElement((UIElement) detailView.Detail);
          canvas2.RenderTransform = (Transform) new ScaleTransform(num1, num1);
          Canvas.SetTop((UIElement) canvas2, 110.0);
          Canvas.SetLeft((UIElement) canvas2, (797.0 - detailView.Detail.Width * num1) / 2.0);
          list[list.Count - 1].Children.Add((UIElement) canvas2);
        }
      }
      return list;
    }

    public static FlowDocument GetTable(List<TableProperty> TableProperties, string TableTitle)
    {
      List<string> list = new List<string>();
      list.Add("XS");
      list.Add("S");
      list.Add("M");
      list.Add("L");
      list.Add("XL");
      list.Add("XXL");
      list.Add("3XL");
      list.Add("4XL");
      list.Add("5XL");
      list.Add("6XL");
      FlowDocument flowDocument = new FlowDocument();
      Table T = new Table();
      T.TextAlignment = TextAlignment.Center;
      T.CellSpacing = 0.0;
      int num = 21;
      for (int index = 0; index < num; ++index)
      {
        T.Columns.Add(new TableColumn());
        T.Columns[index].Width = index != 0 ? new GridLength(16.0) : new GridLength(50.0);
      }
      for (int index1 = 0; index1 < TableProperties.Count + 3; ++index1)
      {
        T.RowGroups.Add(new TableRowGroup());
        T.RowGroups[index1].Rows.Add(new TableRow());
        if (index1 == 0)
        {
          TableRow tableRow = T.RowGroups[index1].Rows[0];
          tableRow.FontSize = 15.0;
          BlockUIContainer blockUiContainer = new BlockUIContainer();
          TextBox textBox = new TextBox();
          blockUiContainer.Child = (UIElement) textBox;
          textBox.Text = !(TableTitle == "") ? TableTitle : "TABLO";
          tableRow.Cells.Add(new TableCell());
          tableRow.Cells[0].ColumnSpan = 21;
          tableRow.Cells[0].Blocks.Add((Block) blockUiContainer);
          tableRow.Cells[0].BorderThickness = new Thickness(1.0);
          tableRow.Cells[0].BorderBrush = (Brush) Brushes.Black;
        }
        else if (index1 == 1)
        {
          TableRow tableRow = T.RowGroups[index1].Rows[0];
          tableRow.FontSize = 12.0;
          for (int index2 = 0; index2 < 11; ++index2)
          {
            tableRow.Cells.Add(new TableCell());
            if (index2 != 0)
            {
              tableRow.Cells[index2].ColumnSpan = 2;
              tableRow.Cells[index2].Blocks.Add((Block) new Paragraph((Inline) new Run(list[index2 - 1])));
              tableRow.Cells[index2].BorderThickness = new Thickness(1.0);
              tableRow.Cells[index2].BorderBrush = (Brush) Brushes.Black;
            }
            else
            {
              tableRow.Cells[index2].Blocks.Add((Block) new Paragraph((Inline) new Run("Beden")));
              tableRow.Cells[index2].BorderThickness = new Thickness(1.0, 1.0, 1.0, 0.0);
              tableRow.Cells[index2].BorderBrush = (Brush) Brushes.Black;
            }
          }
        }
        else if (index1 == 2)
        {
          TableRow tableRow = T.RowGroups[index1].Rows[0];
          tableRow.FontSize = 10.0;
          for (int index2 = 0; index2 < 21; ++index2)
          {
            tableRow.Cells.Add(new TableCell());
            if (index2 != 0)
            {
              tableRow.Cells[index2].Blocks.Add((Block) new Paragraph((Inline) new Run(Convert.ToString(index2 + 34))));
              tableRow.Cells[index2].BorderThickness = new Thickness(1.0);
              tableRow.Cells[index2].BorderBrush = (Brush) Brushes.Black;
            }
            else
            {
              tableRow.Cells[index2].BorderThickness = new Thickness(1.0, 0.0, 1.0, 1.0);
              tableRow.Cells[index2].BorderBrush = (Brush) Brushes.Black;
            }
          }
        }
        else
        {
          TableRow tableRow = T.RowGroups[index1].Rows[0];
          tableRow.FontSize = 10.0;
          for (int index2 = 0; index2 < 21; ++index2)
          {
            tableRow.Cells.Add(new TableCell());
            if (index2 == 0)
            {
              tableRow.Cells[index2].Blocks.Add((Block) new BlockUIContainer()
              {
                Child = (UIElement) new TextBox()
                {
                  Text = TableProperties[index1 - 3].PropertyName
                }
              });
              tableRow.Cells[index2].BorderThickness = new Thickness(1.0);
              tableRow.Cells[index2].BorderBrush = (Brush) Brushes.Black;
            }
            else if (TableProperties[index1 - 3].PropertyValues.Count >= index2)
            {
              BlockUIContainer blockUiContainer = new BlockUIContainer();
              TextBox textBox = new TextBox();
              textBox.Width = 18.0;
              textBox.Text = TableProperties[index1 - 3].PropertyValues[index2 - 1];
              textBox.Tag = (object) ("a" + Convert.ToString(index2));
              textBox.TextChanged += (TextChangedEventHandler) ((s, e) => DetailView.TextChanged(s, e, T));
              if (Enumerable.Count<char>((IEnumerable<char>) textBox.Text) >= 2)
              {
                textBox.Width = (double) (Enumerable.Count<char>((IEnumerable<char>) textBox.Text) * 6 + 7);
                textBox.Name.Replace("a", "");
                T.Columns[index2].Width = new GridLength(textBox.Width);
              }
              blockUiContainer.Child = (UIElement) textBox;
              tableRow.Cells[index2].Blocks.Add((Block) blockUiContainer);
              tableRow.Cells[index2].BorderThickness = new Thickness(1.0);
              tableRow.Cells[index2].BorderBrush = (Brush) Brushes.Black;
            }
            else
            {
              BlockUIContainer blockUiContainer = new BlockUIContainer();
              TextBox textBox = new TextBox();
              textBox.Text = "";
              textBox.Tag = (object) ("a" + Convert.ToString(index2));
              textBox.TextChanged += (TextChangedEventHandler) ((s, e) => DetailView.TextChanged(s, e, T));
              blockUiContainer.Child = (UIElement) textBox;
              tableRow.Cells[index2].Blocks.Add((Block) blockUiContainer);
              tableRow.Cells[index2].BorderThickness = new Thickness(1.0);
              tableRow.Cells[index2].BorderBrush = (Brush) Brushes.Black;
            }
          }
        }
      }
      flowDocument.Blocks.Add((Block) T);
      return flowDocument;
    }

    private static void TextChanged(object sender, TextChangedEventArgs e, Table T)
    {
      TextBox textBox = sender as TextBox;
      if (Enumerable.Count<char>((IEnumerable<char>) textBox.Text) < 2)
        return;
      textBox.Width = (double) (Enumerable.Count<char>((IEnumerable<char>) textBox.Text) * 6 + 7);
      int index = Convert.ToInt32(Convert.ToString(textBox.Tag).Replace("a", ""));
      T.Columns[index].Width = new GridLength(textBox.Width);
    }

    public void DriveDetailView()
    {
      FlowDocument table = DetailView.GetTable(this.TableVeriables, this.TableTitle);
      this.DetailTable = Enumerable.First<Table>(Enumerable.OfType<Table>((IEnumerable) table.Blocks));
      table.Blocks.Clear();
    }

    public static List<TableProperty> GetTableProperties(Table T)
    {
      List<TableProperty> list = new List<TableProperty>();
      TableRowGroupCollection rowGroups = T.RowGroups;
      if (rowGroups.Count >= 4)
      {
        for (int index = 3; index < rowGroups.Count; ++index)
        {
          TableRow tableRow = rowGroups[index].Rows[0];
          TableProperty tableProperty = new TableProperty();
          int num = 0;
          foreach (TableCell tableCell in (IEnumerable<TableCell>) tableRow.Cells)
          {
            if (num == 0)
              tableProperty.PropertyName = ((TextBox) Enumerable.First<BlockUIContainer>(Enumerable.OfType<BlockUIContainer>((IEnumerable) tableCell.Blocks)).Child).Text;
            else
              tableProperty.PropertyValues.Add(((TextBox) Enumerable.First<BlockUIContainer>(Enumerable.OfType<BlockUIContainer>((IEnumerable) tableCell.Blocks)).Child).Text);
            ++num;
          }
          list.Add(tableProperty);
        }
      }
      return list;
    }

    public void UpdateDetailView()
    {
      Table table = this.DetailTable;
      List<TableProperty> list = new List<TableProperty>();
      TableRowGroupCollection rowGroups = table.RowGroups;
      if (rowGroups.Count >= 4)
      {
        for (int index = 3; index < rowGroups.Count; ++index)
        {
          TableRow tableRow = rowGroups[index].Rows[0];
          TableProperty tableProperty = new TableProperty();
          int num = 0;
          foreach (TableCell tableCell in (IEnumerable<TableCell>) tableRow.Cells)
          {
            if (num == 0)
              tableProperty.PropertyName = ((TextBox) Enumerable.First<BlockUIContainer>(Enumerable.OfType<BlockUIContainer>((IEnumerable) tableCell.Blocks)).Child).Text;
            else
              tableProperty.PropertyValues.Add(((TextBox) Enumerable.First<BlockUIContainer>(Enumerable.OfType<BlockUIContainer>((IEnumerable) tableCell.Blocks)).Child).Text);
            ++num;
          }
          list.Add(tableProperty);
        }
      }
      this.TableTitle = ((TextBox) ((BlockUIContainer) table.RowGroups[0].Rows[0].Cells[0].Blocks.LastBlock).Child).Text;
      this.TableVeriables = list;
    }
  }
}
